﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;


namespace CartoGraphic.Model2
{
    public class SimplePoint : DrawingRectangle
    {
        //public LocationPoint lPoint;
        public Point point;
        public SimplePoint()
        {           
            SetRectangle(0, 0, 4, 4);
            Initialize();
        }

        //public LocationPoint LPoint
        //{
        //    get { return lPoint; }
        //    set { lPoint = value; }
        //}

        public Point CenterPoint
        {
            get { return point; }
            set { point = value; }
        }


        public SimplePoint(int x, int y, int width)
        {
            Rectangle = new Rectangle(x, y, width, width);
            Center = new Point(x + (width / 2), y + (width / 2));
            CenterPoint = new Point(x, y);
            TipText = Info;
            Initialize();
        }

        public SimplePoint(Point point,string info)
        {
            int width = 4;
            Rectangle = new Rectangle(point.X, point.Y, width, width);
            Center = new Point(point.X + (width / 2), point.Y + (width / 2));
            CenterPoint = new Point(point.X, point.Y);
            TipText = info;
            Initialize();
        }

        public override BaseDrawingObj Clone()
        {
            SimplePoint newPoint = new SimplePoint();
            newPoint.Rectangle = Rectangle;
            FillDrawObjectFields(newPoint);
            return newPoint;
        }

        public SimplePoint(int x, int y, int width, Color lineColor, Color fillColor, bool filled)
        {
            Rectangle = new Rectangle(x, y, width, width);
            Center = new Point(x + (width / 2), y + (width / 2));
            TipText = Info;
            Color = lineColor;
            FillColor = fillColor;
            Filled = filled;
            Initialize();
        }

        public SimplePoint(int x, int y, int width, bool filled)
        {
            Rectangle = new Rectangle(x, y, width, width);
            Center = new Point(x + (width / 2), y + (width / 2));
            TipText = Info;
            //DrawPen = DrawingPens.SetCurrentPen(pType);
            //PenType = pType;
            //FillColor = fillColor;
            Filled = filled;
            Initialize();
        }

        public SimplePoint(int x, int y, int width, Color lineColor, Color fillColor, bool filled, int lineWidth)
        {
            Rectangle = new Rectangle(x, y, width, width);
            Center = new Point(x + (width / 2), y + (width / 2));
            TipText = Info;
            Color = lineColor;
            FillColor = fillColor;
            Filled = filled;
            PenWidth = lineWidth;
            Initialize();
        }

        public override void MoveHandleTo(Point point, int handleNumber)
        {
            int left = Rectangle.Left;
            int top = Rectangle.Top;
            int right = Rectangle.Right;
            int bottom = Rectangle.Bottom;

            switch (handleNumber)
            {
                case 1:
                    left = point.X;
                    top = point.Y;
                    break;
                case 2:
                    top = point.Y;
                    break;
                case 3:
                    right = point.X;
                    top = point.Y;
                    break;
                case 4:
                    right = point.X;
                    break;
                case 5:
                    right = point.X;
                    bottom = point.Y;
                    break;
                case 6:
                    bottom = point.Y;
                    break;
                case 7:
                    left = point.X;
                    bottom = point.Y;
                    break;
                case 8:
                    left = point.X;
                    break;
            }
            Dirty = true;
            SetRectangle(left, top, right - left, right - left);
        }


        public override void Draw(Graphics g,GraphicsProperties gps)
        {
            Pen pen=new Pen(gps.BorderColor);
            Brush b = new SolidBrush(gps.FillColor);
            GraphicsPath gp = new GraphicsPath();
            gp.AddEllipse(GetNormalizedRectangle(Rectangle));

            g.DrawPath(pen, gp);
            if (gps.Fill)
                g.FillPath(b, gp);
            gp.Dispose();
            pen.Dispose();
            b.Dispose();
        }
    }
}
